<!--GA验证场景设置-->
<template>
  <div class="bg bg1">
    <template v-if="data">

      <VSwitc class="switc" 
      v-model="data.login" 
      :title="T('登录')"
      @change="switcClick('login', $event)"></VSwitc>
      <div class="line line1"></div>

      
      <VSwitc class="switc" 
      v-model="data.deleteApi" 
      :title="T('删除API')"
      @change="switcClick('deleteApi', $event)"></VSwitc>
      <div class="line line1"></div>
      
      
      <VSwitc class="switc" 
      v-model="data.forgetPassword" 
      :title="T('修改登录密码')"
      @change="switcClick('forgetPassword', $event)"></VSwitc>
      <div class="line line1"></div>
      
      <div class="all"></div>
      <div class="btn main-bt1" @click="httpUnbindGa">
        <text class="font30 text1">{{T('解绑谷歌验证器')}}</text>
      </div>
    </template>
  </div>
</template>

<style src="@/_css/style.css" ></style>
<style scoped>
.bg {
  flex: 1;
  padding-left: 40px;
  padding-right: 40px;
}
.switc {
  height:118px;
}
.line{
  height: 1px;
  margin-right: -40px;
}
.btn{
  align-items: center;
  justify-content: center;
  height:80px;
  border-radius:12px;

  margin-bottom:100px;
}
</style>

<script>
//组件
import VSwitc from "@/_public/VSwitc.vue";

//功能
import jnavigator from "@/_js/navigator";
import jhttps from "@/_js/https";
import jmodal from "@/_js/modal";
import jdebug from "@/_js/debug";

const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T('验证场景设置'));

export default {
  
  components: {
    VSwitc,
  },

  data() {
    return {
      T:T,
      data:undefined, //状态表
      authCode:"", 
    };
  },

  mounted() { 
    this.httpGaSetInfo();
  },

  methods: {

    initData(list) {
      var data = {};
      for(var i=0; i<list.length; i++){
        var item = list[i];
        data[item.name] = item.open;
      }
      return data;
    },

    /********************************** HTTP*/
    //https获取Ga设置信息
    httpGaSetInfo(){

      var param = {};
      jhttps.postGa("systemV2/getUserGASeting", param ,true,(data)=>{

        if(data.status == 200){

          data = data.data;
          this.authCode = data.authCode;
          this.data = this.initData(data.authList);
        }else{
          jmodal.toast(data.msg);
        }
      });
    },

    //https设置Ga状态
    httpSetGa(name, status) {
      
      jmodal.showLoad();
      var param = {'name':name, 
                  'status':status,
                  'authCode':this.authCode};
      jhttps.postX("systemV2/userSetGA", param, true,(data)=>{
        jmodal.hideLoad();
        if(data.status == 200){
          jmodal.toast('修改成功');
          this.data[name] = status;
        }else{
          jmodal.toast(data.msg);
          this.data[name] = !status;
        }
      });
    },
    
    //http解绑Ga
    httpUnbindGa(){

      jmodal.showLoad();
      var param = {};
      jhttps.postGa("systemV2/userUnbindGA",param,true,(data)=>{
        jmodal.hideLoad();
        if(data.status == 200){
          jmodal.toast('解绑成功');
          jnavigator.back();
        }else{
          jmodal.toast(data.msg);
        }
      });
    },
    /************************************************* 点击事件*/
    //开关点击
    switcClick(name, status) {
      this.httpSetGa(name,status);
    },
  }
};

</script>
